package com.zhangjm.controller;

import com.zhangjm.User;
import com.zhangjm.fegin.UserFeginClient;
import com.zhangjm.pojo.Order;
import com.zhangjm.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order/")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserFeginClient userFeginClient;

    /**
     * 根据订单Id查询订单信息
     * @param id
     * @return
     */
    @RequestMapping("getById")
    public Order getById(@RequestParam("id") Integer id){
        Order order = orderService.getById(id);
        //调用user服务接口
       // final String username = restTemplate.getForObject("http://localhost:8280/user/getUsernameById?id=111", String.class);
        //service-user是用户服务里面，spring.application.name的名字


        //final String username = restTemplate.getForObject("http://service-user/user/getUsernameById?id=111", String.class);

        User user = userFeginClient.getById(order.getId());
        order.setUsername(user.getUsername());
        return order;
    }
}
